package com.gery.tn.ui.search;

import com.gery.tn.backend.model.Client;
import com.gery.tn.ui.MainWindow;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;




public class ResultList extends JPanel {

    private ArrayList<ResultListItem> results;
    private MainWindow myParent;
    
    
    public ResultList(MainWindow parent) {
        this.setBounds(0, 0, 601, 400);
        this.setBackground(new Color(0, 0, 0, 0));
        this.setLayout(null);
        this.setBorder(null);
        this.setVisible(false);
        this.myParent = parent;
        
        results = new ArrayList<>(10);
        for (int i=0; i<10; i++) {
            results.add(new ResultListItem(i*40, myParent));
            this.add(results.get(i));
        }
    }
    
    
    public void setList(List<Client> items) {
        clearList();
        int itemNr = items.size();
        for (int i=0; i<itemNr; i++) {
            results.get(i).setResult(items.get(i).getID(), items.get(i).getName(), items.get(i).getTel(), Integer.toString(items.get(i).getPoints()));
        }
        this.setVisible(true);
    }
    
    public void fastAppointment() {
        myParent.getAppointmentPanel().panelOn(results.get(0).getID(), results.get(0).getLabelName());
        clearList();
        myParent.getSearchPanel().clearTextField();
        myParent.getAppointmentPanel().setPickerFocus();
    }
    
    public void clearList() {
        for (int i=0; i<10; i++) {
            results.get(i).setVisible(false);
        }
        this.setVisible(false);
    }
    
}
